package com.clothes.adp;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.clothes.R;
import com.clothes.act.CSearch;
import com.clothes.mdoel.ColorInfo;
import com.clothes.views.UnderLineTxt;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/4/5 0005.
 */

public class Cadapter extends BaseAdapter {

    private CSearch context;
    private List<ColorInfo> list;

    public Cadapter(CSearch context, List<ColorInfo> list) {
        this.context = context;
        this.list = list;
    }

    public void setList(List<ColorInfo> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_kh_table2, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        final ColorInfo info = list.get(i);
        holder.tv1.setText(info.getColorName());
        holder.tv2.setText(info.getColorUnClaimed()+"件");
        holder.tv3.setText(info.getColorClaimed()+"件");
        holder.tv4.setText(info.getColorSubmit()+"件");
        holder.tv5.setText((info.getColorUnClaimed()+info.getColorClaimed())+"件");

        holder.tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.showSize(info.getSizeUnClaimedMap());
            }
        });
        holder.tv3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.showSize(info.getSizeClaimedMap());
            }
        });
        holder.tv4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.showSize(info.getSizeSubmitMap());
            }
        });
        holder.tv5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                context.showSize();
            }
        });
        return view;
    }

    public class ViewHolder {
        @Bind(R.id.tv1)
        TextView tv1;
        @Bind(R.id.tv2)
        UnderLineTxt tv2;
        @Bind(R.id.tv3)
        UnderLineTxt tv3;
        @Bind(R.id.tv4)
        UnderLineTxt tv4;
        @Bind(R.id.tv5)
        UnderLineTxt tv5;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
